﻿using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using NHibernate.Expression;
using Castle.ActiveRecord;
using Castle.ActiveRecord.Queries;

namespace Mang24k99.Model.SPECT
{
    [ActiveRecord(Table = "KT_SPECT_DETAILITEMS")]
    public partial class MKtSpectDetailitems : ActiveRecordBase
    {
        public static IList<MKtSpectDetailitems> SelectAll()
        {
            return (IList<MKtSpectDetailitems>)FindAll(typeof(MKtSpectDetailitems));
        }
        public static MKtSpectDetailitems SelectByPrimaryKey(object ID)
        {
            return (MKtSpectDetailitems)FindByPrimaryKey(typeof(MKtSpectDetailitems), ID);
        }
        public static IList<MKtSpectDetailitems> SelectALLByProperty(string property, object value)
        {
            return (IList<MKtSpectDetailitems>)FindAllByProperty(typeof(MKtSpectDetailitems), property, value);
        }
        public static IList<MKtSpectDetailitems> SelectALLSliced(int firstResult, int maxResult, NHibernate.Expression.DetachedCriteria criteria)
        {

            return (IList<MKtSpectDetailitems>)SlicedFindAll(typeof(MKtSpectDetailitems), firstResult, maxResult, criteria);
        }
        protected override void OnDelete()
        {
            MKtSpectDetailitemsHistory mHistory = new MKtSpectDetailitemsHistory();
            Common.ModelCommon.CopyObjectValues(this, mHistory);
            mHistory.SubjectType = MKtSpectSubtype.SubjectType;
            mHistory.DeleteTime = DateTime.Now;
            mHistory.Create();
            base.OnDelete();
        }
        /// <summary>
        /// 根据where条件返回符合条件记录
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public static IList<MKtSpectDetailitems> SelectByWhere(string where)
        {
            string hql = @"from MKtSpectDetailitems detailitems  where "+where;
            SimpleQuery query = new SimpleQuery(typeof(MKtSpectDetailitems),hql);
            return (IList<MKtSpectDetailitems>)ExecuteQuery(query);
        }
        /// <summary>
        /// 删除一条记录
        /// </summary>
        /// <param name="items"></param>
        public static void Delete(MKtSpectDetailitems items)
        {
            items.Delete();
        }

        /// <summary>
        /// 创建一条记录
        /// </summary>
        /// <param name="item"></param>
        public static void Create(MKtSpectDetailitems item)
        {
            item.Create();
        }

        /// <summary>
        /// 选择最大的专题编号
        /// </summary>
        /// <returns></returns>
        public static int GetMaxNO()
        {
            string Hql = @"select max(item.SubjectNO) from MKtSpectDetailitems item  ";
            string count = @"select count(item.SubjectNO) from MKtSpectDetailitems item ";
            ScalarQuery querycount = new ScalarQuery(typeof(MKtSpectDetailitems), count);
            if (Convert.ToInt32(ExecuteQuery(querycount)) == 0)
            {
                return 0;
            }
            ScalarQuery query = new ScalarQuery(typeof(MKtSpectDetailitems), Hql);
            return (int)ExecuteQuery(query);
        }

        [BelongsTo("SUBJECT_TYPE")]
        public MKtSpectSubtype MKtSpectSubtype
        {
            get
            {
                return _MKtSpectSubtype;
            }
            set
            {
                _MKtSpectSubtype = value;
            }
        }


        /// <summary>
        /// Gets or sets the SubjectNO.(主键，每个新的专题新闻条目，该值加一。)
        /// </summary>
        /// <value>The SubjectNO.</value>
        [PrimaryKey(PrimaryKeyType.Assigned, "SUBJECT_NO")]
        public int SubjectNO
        {
            get
            {
                return _SubjectNO;
            }
            set
            {
                _SubjectNO = value;
            }
        }


        /// <summary>
        /// Gets or sets the ID.()
        /// </summary>
        /// <value>The ID.</value>
        [Property("ID", Insert = false, Update = false)]
        public int ID
        {
            get
            {
                return _ID;
            }
            set
            {
                _ID = value;
            }
        }


        /// <summary>
        /// Gets or sets the TITLE.()
        /// </summary>
        /// <value>The TITLE.</value>
        [Property("TITLE")]
        public string TITLE
        {
            get
            {
                return _TITLE;
            }
            set
            {
                _TITLE = value;
            }
        }


        /// <summary>
        /// Gets or sets the ADDRESS.()
        /// </summary>
        /// <value>The ADDRESS.</value>
        [Property("ADDRESS")]
        public string ADDRESS
        {
            get
            {
                return _ADDRESS;
            }
            set
            {
                _ADDRESS = value;
            }
        }


        /// <summary>
        /// Gets or sets the RelateAdd.()
        /// </summary>
        /// <value>The RelateAdd.</value>
        [Property("RELATE_ADD")]
        public string RelateAdd
        {
            get
            {
                return _RelateAdd;
            }
            set
            {
                _RelateAdd = value;
            }
        }


        /// <summary>
        /// Gets or sets the OrderNO.()
        /// </summary>
        /// <value>The OrderNO.</value>
        [Property("ORDER_NO")]
        public int? OrderNO
        {
            get
            {
                return _OrderNO;
            }
            set
            {
                _OrderNO = value;
            }
        }


        /// <summary>
        /// Gets or sets the IsValidate.()
        /// </summary>
        /// <value>The IsValidate.</value>
        [Property("IS_VALIDATE")]
        public int? IsValidate
        {
            get
            {
                return _IsValidate;
            }
            set
            {
                _IsValidate = value;
            }
        }


        /// <summary>
        /// Gets or sets the InputTime.()
        /// </summary>
        /// <value>The InputTime.</value>
        [Property("INPUT_TIME")]
        public DateTime? InputTime
        {
            get
            {
                return _InputTime;
            }
            set
            {
                _InputTime = value;
            }
        }


        /// <summary>
        /// Gets or sets the ModifyTime.()
        /// </summary>
        /// <value>The ModifyTime.</value>
        [Property("MODIFY_TIME")]
        public DateTime? ModifyTime
        {
            get
            {
                return _ModifyTime;
            }
            set
            {
                _ModifyTime = value;
            }
        }


        /// <summary>
        /// Gets or sets the DeleteTime.()
        /// </summary>
        /// <value>The DeleteTime.</value>
        [Property("DELETE_TIME")]
        public DateTime? DeleteTime
        {
            get
            {
                return _DeleteTime;
            }
            set
            {
                _DeleteTime = value;
            }
        }



        private int _SubjectNO;

        private IList<MKtSpectDetailitems> _MKtSpectDetailitems;
        private int _ID;

        private string _TITLE;

        private string _ADDRESS;

        private string _RelateAdd;

        private MKtSpectSubtype _MKtSpectSubtype;
        private int? _OrderNO;

        private int? _IsValidate;

        private DateTime? _InputTime;

        private DateTime? _ModifyTime;

        private DateTime? _DeleteTime;


    }
}
